<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="" autocomplete="off">
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">职业类型：</label>
        <div class="col-xs-12 col-sm-8">
            <div class="radio">
                <label for="user_type-1"><input class="form-input-type" id="user_type-1" name="user_type" type="radio" value="1" onchange="change_type(this);" checked> 学生家长</label>
                <label for="user_type-2"><input class="form-input-type"  id="user_type-2" name="user_type" type="radio" value="2" onchange="change_type(this);"> 教职工</label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label class="control-label col-xs-12 col-sm-2">{:__('Org_cate_id')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select  id="c-org_cate_id" data-rule="required" class="form-control selectpicker" name="row[org_cate_id]" onchange="change_cate(this)">
                {foreach name="orgName_tree" item="vo"}
                <option value="{$key}" {in name="key" value="0"}selected{/in}>{$vo}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="form-group parent_cla">
        <label class="control-label col-xs-12 col-sm-2">{:__('班级')}:</label>
        <div class="col-xs-12 col-sm-8">
            <select  id="c-parent_id" class="form-control" name="row[parent_id]" onchange="change_group(this)">
                <option value="0" selected>顶级</option>
            </select>
        </div>
    </div>


    <div class="form-group layer-footer">
        <input type="hidden" id="type" name="type" value="1">
        <input type="hidden" id="gropuid" name="groupid" value="0">
        <label class="control-label col-xs-12 col-sm-2"></label>
        <div class="col-xs-12 col-sm-8">
            <button type="button" href="javascript:;" class="btn btn-info btn-import {:$auth->check('user/user/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="user/user/import" data-mimetype="csv" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</button>
            <a href="/template/userimport.csv"  target="_blank" id="stud" class="btn btn-info">学生家长CSV模版</a>
            <a href="/template/userimport2.csv" target="_blank" id="teac" class="btn btn-info hide">教职工CSV模版</a>
        </div>
    </div>
</form>
<script>
    function change_cate(obj){
        var cate_id = $(obj).val();
        $.ajax({
            url:'ajax/orggroup2',
            data: {cate_id:cate_id},
            type:'POST',
            dataType: "json",
            success: function (res) {
                htmls ='<option value="0" selected>顶级</option>';
                $('#gropuid').val(0);
                if(res.data.level != 3){
                    Toastr.error('请选择三级行业');
                }else{
                    var list = res.data.groups;
                    if(list.length > 0){
                        htmls = '';
                        for(let i = 0; i<list.length;i++){
                            if(i == 0){
                                $('#gropuid').val(list[i].id);
                            }
                            htmls+=' <option value="'+list[i].id+'">'+list[i].name+'</option>';
                        }
                    }
                }
                $('#c-parent_id').html(htmls);
                change_url();
            }
        });
    }
    function change_type(obj){
        var type = $(obj).val();
        if(type == 1){
            $("#stud").removeClass('hide');
            $("#teac").addClass('hide');
        }else{
            $("#teac").removeClass('hide');
            $("#stud").addClass('hide');
        }
        $('#type').val(type);
        change_url();
    }
    function change_group(obj){
        var gropuid = $(obj).val();
        $('#gropuid').val(gropuid);
        change_url();
    }

    function change_url()
    {
        var type = $('#type').val();
        var gropuid = $('#gropuid').val();
        var url = 'user/user/import?type='+type+'&groupid='+gropuid;
        $.ajax({
            url:'user/user/setSess',
            data: {type:type,gropuid:gropuid},
            type:'POST',
            dataType: "json",
            success: function (res) {
//                console.log(res);
            }
        });
    }
</script>
